﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using TConfig;

public class TMapManager : MonoBehaviour {
	
	/// <summary>
	/// 加载精灵的类型
	/// </summary>
	enum LoadSpriteTypeEnum
	{
		Map,						//地图类型
		Monster,					//怪物类型
		Hero,						//英雄类型
		Bullet,						//子弹类型
	}
	
	
	int currMapId;		//当前的地图Id
	int currCount;		//当前已经加载的对象数量
	int totalCount;		//总共需要加载的对象数量
	List<SceneObj> mapList = new List<SceneObj>();
	List<SpriteObj> spriteList = new List<SpriteObj>();
	List<SpriteObj> heroList = new List<SpriteObj>();
	List<BulletObj> bulletList = new List<BulletObj>();
	
	public static Dictionary<string, UIManager.MaterialAsset> materialList = new Dictionary<string, UIManager.MaterialAsset>();
	public static Dictionary<string, UIManager.AtlasAsset> atlasList = new Dictionary<string, UIManager.AtlasAsset>();
	static Dictionary<string, UIManager.MaterialRecordes> cacheMaterialList = new Dictionary<string, UIManager.MaterialRecordes>();//材质资源还没有加载的时候的材质空间缓存
	static Dictionary<string, UIManager.AtlasRecordes> cacheAtlasList = new Dictionary<string, UIManager.AtlasRecordes>();
	
	
	static TMapManager instance;
	
	public static TMapManager GetInstace()
	{
		return instance;
	}
	
	void Awake()
	{
		instance = this;
	}
	
	public void LoadMapInfo(string levelName)
	{
		currCount = 0;
		totalCount = 0;
		LoadMap(levelName);
		LoadSprite(levelName);
		
		LoadBullet();
	}
	
	void ObjLoadOver()
	{
		currCount++;
		if(currCount >= totalCount)
		{
			//其实在这里应该设置在加载资源管理里面设置，现在没有设置此manager 所以说先在这里调用下数据吧
			Thero.GetInstance().OnLoadOverMap();
		}
	}
	
	#region 加载精灵资源列表
	
	/// <summary>
	/// 加载 精灵
	/// </summary>
	void LoadSprite(string levelName)
	{
		LoadHero(levelName);
		LoadMonster(levelName);
	}
	
	/// <summary>
	/// 加载地图资源数据
	/// </summary>
	void LoadMap(string levelName)
	{
		string url = GameResources.GetMapFileName(levelName);
		LoadXML.GetInstance().InitLoadXml(url, this, this.GetType().GetMethod("LoadMapXMLText"), LoaderManager.LoadTypeEnum.XML);
	}
	
	/// <summary>
	/// 加载怪物资源
	/// </summary>
	void LoadMonster(string levelName)
	{
		string url = GameResources.GetMonsterFileName(levelName);
		LoadXML.GetInstance().InitLoadXml(url, this, this.GetType().GetMethod("LoadMonsterXMLText"), LoaderManager.LoadTypeEnum.XML);
	}
	
	/// <summary>
	/// 加载 hero资源
	/// </summary>
	void LoadHero(string levelName)
	{
		string url = GameResources.GetHeroFileName();
		LoadXML.GetInstance().InitLoadXml(url, this, this.GetType().GetMethod("LoadHeroXMLText"), LoaderManager.LoadTypeEnum.XML);
	}
	
	/// <summary>
	/// 加载 Bullet 资源
	/// </summary>
	void LoadBullet()
	{
		string url = GameResources.GetBulletName();
		LoadXML.GetInstance().InitLoadXml(url, this, this.GetType().GetMethod("LoadBulletXMLText"), LoaderManager.LoadTypeEnum.XML);
	}
	
	public void LoadMapXMLText(object obj, object type)
	{
		string xml = obj as string;
		XmlDocument xmlDoc = new XmlDocument(); 
		xmlDoc.LoadXml(xml); 
		System.Xml.XmlNodeList Block = xmlDoc.GetElementsByTagName("ArrayOfSceneObj");
		if(Block.Count>0)
		{
			XmlElement coun = (XmlElement)Block.Item(0);
			ReadMapElement(coun);
		}
	}
	
	public void LoadMonsterXMLText(object obj, object type)
	{
		string xml = obj as string;
		XmlDocument xmlDoc = new XmlDocument(); 
		xmlDoc.LoadXml(xml); 
		System.Xml.XmlNodeList Block = xmlDoc.GetElementsByTagName("ArrayOfSpriteObj");
		if(Block.Count>0)
		{
			XmlElement coun = (XmlElement)Block.Item(0);
			ReadSpriteElement(coun, LoadSpriteTypeEnum.Monster);
		}
	}
	
	public void LoadHeroXMLText(object obj, object type)
	{
		string xml = obj as string;
		XmlDocument xmlDoc = new XmlDocument(); 
		xmlDoc.LoadXml(xml); 
		System.Xml.XmlNodeList Block = xmlDoc.GetElementsByTagName("ArrayOfSpriteObj");
		if(Block.Count>0)
		{
			XmlElement coun = (XmlElement)Block.Item(0);
			ReadSpriteElement(coun, LoadSpriteTypeEnum.Hero);
		}
	}
	
	public void LoadBulletXMLText(object obj, object type)
	{
		string xml = obj as string;
		XmlDocument xmlDoc = new XmlDocument(); 
		xmlDoc.LoadXml(xml); 
		System.Xml.XmlNodeList Block = xmlDoc.GetElementsByTagName("ArrayOfBulletObj");
		if(Block.Count>0)
		{
			XmlElement coun = (XmlElement)Block.Item(0);
			ReadBulletElement(coun, LoadSpriteTypeEnum.Bullet);
		}
	}
	
	void ReadMapElement(XmlElement blockele)
	{
		if(blockele.ChildNodes.Count==0)
		{
			return;
		}
		mapList.Clear();
		XmlNode infonode = blockele.FirstChild;
		while(infonode!=null)
		{
			XmlElement pinfoele = (XmlElement)infonode;
			
			SceneObj obj = new SceneObj();
			obj.name = pinfoele.GetAttribute("name");
			obj.parentName = pinfoele.GetAttribute("parentName");
			obj.positionX = float.Parse(pinfoele.GetAttribute("positionX"));
			obj.positionY = float.Parse(pinfoele.GetAttribute("positionY"));
			obj.positionZ = float.Parse(pinfoele.GetAttribute("positionZ"));
			obj.rotationX = float.Parse(pinfoele.GetAttribute("rotationX"));
			obj.rotationY = float.Parse(pinfoele.GetAttribute("rotationY"));
			obj.rotationZ = float.Parse(pinfoele.GetAttribute("rotationZ"));
			obj.scaleX = float.Parse(pinfoele.GetAttribute("scaleX"));
			obj.scaleY = float.Parse(pinfoele.GetAttribute("scaleY"));
			obj.scaleZ = float.Parse(pinfoele.GetAttribute("scaleZ"));
			obj.prefabPath = pinfoele.GetAttribute("prefabPath");
			
			mapList.Add(obj);
			
			infonode=infonode.NextSibling;
		}
		
		LoadPrefab(LoadSpriteTypeEnum.Map);
	}
	
	void ReadSpriteElement(XmlElement blockele, LoadSpriteTypeEnum type)
	{
		if(blockele.ChildNodes.Count==0)
		{
			return;
		}
		if(type == LoadSpriteTypeEnum.Monster)
			spriteList.Clear();
		else
			heroList.Clear();
		
		XmlNode infonode = blockele.FirstChild;
		while(infonode!=null)
		{
			XmlElement pinfoele = (XmlElement)infonode;
			
			SpriteObj obj = new SpriteObj();
			obj.name = pinfoele.GetAttribute("name");
			obj.parentName = pinfoele.GetAttribute("parentName");
			obj.positionX = float.Parse(pinfoele.GetAttribute("positionX"));
			obj.positionY = float.Parse(pinfoele.GetAttribute("positionY"));
			obj.positionZ = float.Parse(pinfoele.GetAttribute("positionZ"));
			obj.rotationX = float.Parse(pinfoele.GetAttribute("rotationX"));
			obj.rotationY = float.Parse(pinfoele.GetAttribute("rotationY"));
			obj.rotationZ = float.Parse(pinfoele.GetAttribute("rotationZ"));
			obj.scaleX = float.Parse(pinfoele.GetAttribute("scaleX"));
			obj.scaleY = float.Parse(pinfoele.GetAttribute("scaleY"));
			obj.scaleZ = float.Parse(pinfoele.GetAttribute("scaleZ"));
			obj.prefabPath = pinfoele.GetAttribute("prefabPath");
			
			obj.hp = int.Parse(pinfoele.GetAttribute("hp"));
			obj.mp = int.Parse(pinfoele.GetAttribute("mp"));
			obj.attack = int.Parse(pinfoele.GetAttribute("attack"));
			obj.attackType = int.Parse(pinfoele.GetAttribute("attackType"));
			obj.defense = int.Parse(pinfoele.GetAttribute("defense"));
			obj.attackFrequency = float.Parse(pinfoele.GetAttribute("attackFrequency"));
			obj.attackDistance = float.Parse(pinfoele.GetAttribute("attackDistance"));
			obj.speedX = float.Parse(pinfoele.GetAttribute("speedX"));
			obj.speedY = float.Parse(pinfoele.GetAttribute("speedY"));
			obj.xPingPongLength = int.Parse(pinfoele.GetAttribute("xPingPongLength"));
			obj.yStopPos = int.Parse(pinfoele.GetAttribute("yStopPos"));
			obj.bulletId = int.Parse(pinfoele.GetAttribute("bulletId"));
			obj.moveType = int.Parse(pinfoele.GetAttribute("moveType"));
			
			if(type == LoadSpriteTypeEnum.Monster)
				spriteList.Add(obj);
			else
				heroList.Add(obj);
			
			infonode=infonode.NextSibling;
		}
		
		LoadPrefab(type);
	}
	
	void ReadBulletElement(XmlElement blockele, LoadSpriteTypeEnum type)
	{
		if(blockele.ChildNodes.Count==0)
		{
			return;
		}
		bulletList.Clear();
		XmlNode infonode = blockele.FirstChild;
		while(infonode!=null)
		{
			XmlElement pinfoele = (XmlElement)infonode;
			BulletObj obj = new BulletObj();
			obj.id = int.Parse(pinfoele.GetAttribute("id"));
			obj.speed = float.Parse(pinfoele.GetAttribute("speed"));
			obj.bulletType = int.Parse(pinfoele.GetAttribute("bulletType"));
			obj.moveType = int.Parse(pinfoele.GetAttribute("moveType"));
			obj.filePath = pinfoele.GetAttribute("filePath");
			
			bulletList.Add(obj);
			infonode=infonode.NextSibling;
		}
		
		LoadPrefab(type);
	}
	
	/// <summary>
	/// 加载预设资源
	/// </summary>
	void LoadPrefab(LoadSpriteTypeEnum type)
	{
		
		switch(type)
		{
		case LoadSpriteTypeEnum.Map:
			if(mapList.Count == 0)
			{
				Debug.LogError("没有地图资源列表");
				return;
			}
			
			for(int i = 0; i < mapList.Count; i++)
			{
				totalCount++;
				TObjectManager.GetInstances().Load(i, GameResources.LocalPath + mapList[i].prefabPath, OnMapLoadOver);
			}
			break;
		case LoadSpriteTypeEnum.Monster:
			if(spriteList.Count == 0)
			{
				Debug.LogError("没有精灵资源列表");
				return;
			}
			
			for(int i = 0; i < spriteList.Count; i++)
			{
				totalCount++;
				TObjectManager.GetInstances().Load(i, GameResources.LocalPath + spriteList[i].prefabPath, OnMonsterLoadOver);
			}
			break;
		case LoadSpriteTypeEnum.Hero:
			if(heroList.Count == 0)
			{
				Debug.LogError("没有精灵资源列表");
				return;
			}
			
			for(int i = 0; i < heroList.Count; i++)
			{
				totalCount++;
				int parmeter = Thero.GetInstance().GetOffsetHeroType(i, heroList[i].prefabPath);
				TObjectManager.GetInstances().Load(parmeter, GameResources.LocalPath + heroList[i].prefabPath, OnHeroLoadOver);
			}
			break;
		case LoadSpriteTypeEnum.Bullet:
			if(bulletList.Count == 0)
			{
				Debug.LogError("没有精灵资源列表");
				return;
			}
			for(int i = 0; i < bulletList.Count; i++)
			{
				totalCount++;
//				int parmeter = Thero.GetInstance().GetOffsetHeroType(i, heroList[i].prefabPath);
				TObjectManager.GetInstances().Load(i, GameResources.LocalPath + bulletList[i].filePath, OnBulletLoadOver);
			}
			break;
		}
	}
	
	#endregion 加载精灵资源列表
	
	#region 列表资源对象加载完成
	
	/// <summary>
	/// 地图列表中的地图对象下载完成
	/// </summary>
	void OnMapLoadOver(object obj, TMyFile www)
	{
		if(www == null)
			return;

		int index = (int)obj;
		
		GameObject go = Instantiate(www.obj) as GameObject;
		go.SetActiveRecursively(true);
		go.name = mapList[index].name;
		
		ObjectManager.GetInstance().ResetModel(go);
		go.transform.localPosition = new Vector3(mapList[index].positionX,
			mapList[index].positionY, mapList[index].positionZ);
		go.transform.localRotation = Quaternion.Euler(mapList[index].rotationX,
			mapList[index].rotationY, mapList[index].rotationZ);
		go.transform.localScale = new Vector3(mapList[index].scaleX,
			mapList[index].scaleY, mapList[index].scaleZ);
		
		SetMaterial(go);
		
		ObjLoadOver();
	}
	
	/// <summary>
	/// 怪物列表中的怪物对象加载完成
	/// </summary>
	void OnMonsterLoadOver(object obj, TMyFile www)
	{
		if(www == null)
			return;

		int index = (int)obj;
		
		GameObject go = Instantiate(www.obj) as GameObject;
		go.SetActiveRecursively(true);
		go.name = spriteList[index].name;
		
		ObjectManager.GetInstance().ResetModel(go);
		go.transform.localPosition = new Vector3(spriteList[index].positionX,
			spriteList[index].positionY, spriteList[index].positionZ);
		go.transform.localRotation = Quaternion.Euler(spriteList[index].rotationX,
			spriteList[index].rotationY, spriteList[index].rotationZ);
		go.transform.localScale = new Vector3(spriteList[index].scaleX,
			spriteList[index].scaleY, spriteList[index].scaleZ);
		
		TMonster mon = go.GetComponent<TMonster>();
		mon.Hp = spriteList[index].hp;
		mon.Mp = spriteList[index].mp;
		mon.AttackValue = spriteList[index].attack;
		mon.AttackType = (AttackTypeEnum)spriteList[index].attackType;
		mon.AttackDistance = spriteList[index].attackDistance;
		mon.AttackFrequency = spriteList[index].attackFrequency;
		mon.DefenseValue = spriteList[index].defense;
		mon.SpeedX = spriteList[index].speedX;
		mon.SpeedY = spriteList[index].speedY;
		mon.XPingPongLength = spriteList[index].xPingPongLength;
		mon.YStopPos = spriteList[index].yStopPos;
		mon.BulletId = spriteList[index].bulletId;
		mon.MoveType = (MoveTypsEnum)spriteList[index].moveType;
		
		SetAtlas(go);
		
		ObjLoadOver();
	}
	
	/// <summary>
	/// 英雄列表中的怪物对象加载完成
	/// </summary>
	void OnHeroLoadOver(object obj, TMyFile www)
	{
		if(www == null)
			return;

		int index = (int)obj;
		var heroType = Thero.GetInstance().GetHeroType(index);
		index = Thero.GetInstance().GetHeroIndex(index);
		
		GameObject go = Instantiate(www.obj) as GameObject;
		go.SetActiveRecursively(true);
		go.name = heroList[index].name;
		
		ObjectManager.GetInstance().ResetModel(go);
		
		Thero.GetInstance().SetHeroType(go, heroType);
		
		go.transform.localPosition = new Vector3(heroList[index].positionX,
			heroList[index].positionY, heroList[index].positionZ);
		go.transform.localRotation = Quaternion.Euler(heroList[index].rotationX,
			heroList[index].rotationY, heroList[index].rotationZ);
//		go.transform.localPosition = Vector3.zero;
//		go.transform.localRotation = Quaternion.Euler(Vector3.zero);
		go.transform.localScale = new Vector3(heroList[index].scaleX,
			heroList[index].scaleY, heroList[index].scaleZ);
		
		TTeam team = go.GetComponent<TTeam>();
		team.Hp = heroList[index].hp;
		team.Mp = heroList[index].mp;
		team.AttackValue = heroList[index].attack;
		team.AttackType = (AttackTypeEnum)heroList[index].attackType;
		team.AttackDistance = heroList[index].attackDistance;
		team.AttackFrequency = heroList[index].attackFrequency;
		team.DefenseValue = heroList[index].defense;
		team.SpeedX = heroList[index].speedX;
		team.SpeedY = heroList[index].speedY;
		team.XPingPongLength = heroList[index].xPingPongLength;
		team.YStopPos = heroList[index].yStopPos;
		team.BulletId = heroList[index].bulletId;
		team.MoveType = (MoveTypsEnum)heroList[index].moveType;
		
		SetAtlas(go);
		
		ObjLoadOver();
	}
	
	/// <summary>
	/// 子弹列表中的对象加载完成
	/// </summary>
	void OnBulletLoadOver(object obj, TMyFile www)
	{
		if(www == null)
			return;
		int index = (int)obj;
		
		GameObject go = Instantiate(www.obj) as GameObject;
		go.SetActiveRecursively(true);
		ObjectManager.GetInstance().ResetModel(go);
		
		go.name = bulletList[index].id.ToString();
		go.transform.localPosition = Vector3.zero;
		go.transform.localRotation = Quaternion.Euler(Vector3.zero);
		
		var e = BulletManager.CreateEffectObj(bulletList[index].id.ToString(),
												go, go.GetComponent<TSprite>());
		
		//添加到对象模板列表中
		BulletManager.AddEffectObjModel(go.name, go);
		
		TBullet bullet = go.GetComponent<TBullet>();
		bullet.Obj = e;
		bullet.Id = bulletList[index].id;
		bullet.MoveSpeed = bulletList[index].speed;
		bullet.BulletType = (BulletTypeEnum)bulletList[index].bulletType;
		bullet.BulletMoveType = (BulletMoveTypeEnum)bulletList[index].moveType;
		
		SetAtlas(go);
		ObjLoadOver();
	}
	
	#endregion 列表资源对象加载完成
	
	/// <summary>
	/// 设置材质
	/// </summary>
	void SetMaterial(GameObject go)
	{
		Dictionary<string, UIManager.MaterialRecordes> materialList = new Dictionary<string, UIManager.MaterialRecordes>();
		
		List<UIWidget> widgets = NGUITools.FindInChildren<UIWidget>(go);
		foreach(UIWidget widget in widgets)
		{
			string srcPath = widget.srcPath;
			if(!string.IsNullOrEmpty(srcPath))
			{
				if(widget is UITexture)
				{
					UITexture texture = widget as UITexture;				
					if(texture.mustLoad)
					{
						texture.mustLoad = false;
						if(!materialList.ContainsKey(srcPath))
							materialList.Add(srcPath, new UIManager.MaterialRecordes());
						materialList[srcPath].textureList.Add(texture);
					}
				}
			}
		}
		
		foreach(string filePath in materialList.Keys)
		{
			Material material = GetMaterial(filePath);
			if(material != null)
			{
				UIManager.MaterialRecordes recordes = materialList[filePath];
				foreach(UITexture texture in recordes.textureList)
				{
					texture.material = material;
				}
			}
			else
			{
				string path = UIManager.GetTrueFilePath(filePath, UIManager.UIResourcesType.Material);
				if(cacheMaterialList.ContainsKey(path))
					cacheMaterialList[path].textureList.AddRange(materialList[filePath].textureList);
				else
					cacheMaterialList.Add(path, materialList[filePath]);
				totalCount++;
			}
		}
	}
	
	Material GetMaterial(string filePath)
	{
		if(string.IsNullOrEmpty(filePath))
			return null;
		
		filePath = UIManager.GetTrueFilePath(filePath, UIManager.UIResourcesType.Material);
		Material material = null;
		if(materialList.ContainsKey(filePath))
			material = materialList[filePath].material;
		
		if(material == null)
			TObjectManager.GetInstances().Load(null, filePath, OnLoadOverMaterial);
		
		return material;
	}
	
	void OnLoadOverMaterial(object obj, TMyFile www)
	{
		if(www == null)
			return;
		UIManager.MaterialAsset assetInfo = new UIManager.MaterialAsset();
		assetInfo.filePath = www.url;
		assetInfo.material = www.obj as Material;
		SetMaterial(assetInfo);
	}
	
	void SetMaterial(UIManager.MaterialAsset materialAsset)
	{
		if(materialAsset == null)
			return;
		
		if(materialList.ContainsKey(materialAsset.filePath))
			materialList.Remove(materialAsset.filePath);
		materialList.Add(materialAsset.filePath, materialAsset);
		
		foreach(string filePath in cacheMaterialList.Keys)
		{
			if(string.Equals(filePath, materialAsset.filePath))
			{
				Material material = materialAsset.material;
				if(material != null)
				{
					UIManager.MaterialRecordes recordes = cacheMaterialList[filePath];
					foreach(UITexture texture in recordes.textureList)
					{
						texture.material = material;
					}
				}
			}
		}
		if(cacheMaterialList.ContainsKey(materialAsset.filePath))
			cacheMaterialList.Remove(materialAsset.filePath);
		ObjLoadOver();
	}
	
	/// <summary>
	/// 设置图集
	/// </summary>
	void SetAtlas(GameObject go)
	{
		Dictionary<string, UIManager.AtlasRecordes> atlaslList = new Dictionary<string, UIManager.AtlasRecordes>();
		
		List<UIWidget> widgets = NGUITools.FindInChildren<UIWidget>(go);
		foreach(UIWidget widget in widgets)
		{
			string srcPath = widget.srcPath;
			if(!string.IsNullOrEmpty(srcPath))
			{
				if(widget is UISprite)
				{
					UISprite sprite = widget as UISprite;				
					if(sprite.mustLoad)
					{
						sprite.mustLoad = false;
						if(!atlaslList.ContainsKey(srcPath))
							atlaslList.Add(srcPath, new UIManager.AtlasRecordes());
						atlaslList[srcPath].spriteList.Add(sprite);
					}
				}
			}
		}
		
		foreach(string filePath in atlaslList.Keys)
		{
			UIAtlas atlas = GetAtlas(filePath);
			if(atlas != null)
			{
				UIManager.AtlasRecordes recordes = atlaslList[filePath];
				foreach(UISprite sprite in recordes.spriteList)
				{
					sprite.atlas = atlas;
					var t = sprite.gameObject.GetComponent<TSprite>();
					if(t != null)
					{
						t.OnSpriteLoadOverAtals();
					}
				}
			}
			else
			{
				string path = UIManager.GetTrueFilePath(filePath, UIManager.UIResourcesType.Atlas);
				if(cacheAtlasList.ContainsKey(path))
					cacheAtlasList[path].spriteList.AddRange(atlaslList[filePath].spriteList);
				else
					cacheAtlasList.Add(path, atlaslList[filePath]);
				totalCount++;
			}
		}
	}
	
	UIAtlas GetAtlas(string filePath)
	{
		if(string.IsNullOrEmpty(filePath))
			return null;
		
		filePath = UIManager.GetTrueFilePath(filePath, UIManager.UIResourcesType.Atlas);
		UIAtlas atlas = null;
		if(atlasList.ContainsKey(filePath))
			atlas = atlasList[filePath].atlas;
		
		if(atlas == null)
			TObjectManager.GetInstances().Load(null, filePath, OnLoadOverAtlas);
		
		return atlas;
	}
	
	void OnLoadOverAtlas(object obj, TMyFile www)
	{
		if(www == null)
			return;
		UIManager.AtlasAsset assetInfo = new UIManager.AtlasAsset();
		assetInfo.filePath = www.url;
		assetInfo.atlas = (www.obj as GameObject).GetComponent<UIAtlas>();
		SetAtlas(assetInfo);
	}
	
	void SetAtlas(UIManager.AtlasAsset atlasAsset)
	{
		if(atlasAsset == null)
			return;
		
		if(atlasList.ContainsKey(atlasAsset.filePath))
			atlasList.Remove(atlasAsset.filePath);
		atlasList.Add(atlasAsset.filePath, atlasAsset);
		
		foreach(string filePath in cacheAtlasList.Keys)
		{
			if(string.Equals(filePath, atlasAsset.filePath))
			{
				UIAtlas atlas = atlasAsset.atlas;
				if(atlas != null)
				{
					UIManager.AtlasRecordes recordes = cacheAtlasList[filePath];
					foreach(UISprite sprite in recordes.spriteList)
					{
						sprite.atlas = atlas;
						var t = sprite.gameObject.GetComponent<TSprite>();
						if(t != null)
						{
							t.OnSpriteLoadOverAtals();
						}
					}
				}
			}
		}
		if(cacheAtlasList.ContainsKey(atlasAsset.filePath))
			cacheAtlasList.Remove(atlasAsset.filePath);
		ObjLoadOver();
	}
}
